// utils/response.js
class ApiResponse {
    constructor(success, code, message, data = null) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 成功响应
    static success(data = null, message = "操作成功", code = 200) {
        return new ApiResponse(true, code, message, data);
    }

    // 失败响应
    static error(message = "操作失败", code = 500, data = null) {
        return new ApiResponse(false, code, message, data);
    }

    // 未找到响应
    static notFound(message = "资源不存在", data = null) {
        return new ApiResponse(false, 404, message, data);
    }

    // 未授权响应
    static unauthorized(message = "未授权", data = null) {
        return new ApiResponse(false, 401, message, data);
    }

    // 禁止访问响应
    static forbidden(message = "禁止访问", data = null) {
        return new ApiResponse(false, 403, message, data);
    }

    // 验证错误响应
    static validationError(errors = [], message = "验证失败") {
        return new ApiResponse(false, 400, message, errors);
    }
}

module.exports = ApiResponse;